package paint;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.Line2D;
import java.awt.image.BufferedImage;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.tree.DefaultMutableTreeNode;


public class LineUnder {

	BufferedImage bimg;
	public static BufferedImage buff;
	public static JFrame frame;
	public JButton btn1;
	public static JSlider progress;
	
	LineUnder() {
		frame = new JFrame("test");
		frame.setPreferredSize(new Dimension(500, 500));
		JPanel pnl = new panel();
		
		frame.getContentPane().add(pnl);
		frame.addWindowListener(new WindowAdapter() {
        
			public void windowClosing(WindowEvent event) {
                System.exit(0);
            }
        });


		frame.setSize(new Dimension (500, 500));
		frame.pack();
		frame.setVisible(true);

	}

	public static void main(String[] args) {
		LineUnder l = new LineUnder();
		//LineUnder.runs(10);
		
		
	}


	
	

	class myButton extends JButton {
		public myButton(String txt) {
			super(new String(txt));
			setPreferredSize(new Dimension(50, 20));
			
		}

		public void paintComponent(Graphics g) {
			Graphics2D g2 = (Graphics2D) g;
			
			//System.out.println("Button hash: " + this.hashCode());
			//GradientPaint p;
			//p = new GradientPaint(0, 0, Color.RED, 0, getHeight(), Color.BLUE);
			System.out.println("BTN1: " + this.getLocation());
			//Paint oldPaint = g2.getPaint();
			//g2.setPaint(p);
			//g2.fillRect(0, 0, getWidth(), getHeight());
			//g2.setPaint(oldPaint);
			
			g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
					RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
			super.paintComponent(g);
			
		}

	}

	class panel extends JPanel {
		panel() {
			this.setPreferredSize(new Dimension(110, 110));
		}

		public void paintComponent(Graphics g) {

			
			Graphics2D g2 = (Graphics2D) g;

			//gc.drawRect(30, 10, 20, 20);
			g2.setColor(Color.green);
			g2.fillRect(10, 20, 30, 40);
			g2.setColor(Color.blue);
			g2.fillRect(70, 50, 90, 100);
			
			g2.drawLine(30, 40, 50, 70);
			Shape shape = new Line2D.Double(10, 20, 50, 40);
			System.out.println("Shape: " + shape.getBounds().getMaxX());
			
			//g2.drawImage(bimg, null, 0, 0);

		}
	}

}